import axios from 'axios'
import local from '@/utils/local'
import { Message } from 'element-ui';

axios.defaults.baseURL="http://127.0.0.1:5000"
axios.defaults.timeout = 10000

axios.interceptors.request.use(config=>{
    let token = local.get('t_k')
   
    if(token){
        config.headers.authorization = token
    }
    return config
},error=>{
    console.log(error);
    return Promise.reject(error)
    
})

axios.interceptors.response.use(
    response=>{

        let {code,msg}= response.data

        if(code==0){
            Message({
                type:"success",message:msg
            })
        }
        if(code==1){
            Message.error(msg) 
        }
        return response
    },
    error =>{
        // if(error.data.code===401){

        //     local.clear()
        //     window.location.href  = 'http://localhost:8080/#/login'
        // }
        return Promise.reject(error)
    }
)
export default axios